# models/price_predictor.py

import torch.nn as nn
import json
from models.dynamic_builder import DynamicModelBuilder

class PricePredictor(nn.Module):
    def __init__(self, config_path, input_dim):
        super().__init__()
        with open(config_path, "r") as f:
            config = json.load(f)["model"]

        self.layers = nn.ModuleList()
        curr_dim = input_dim

        for layer_cfg in config["layers"]:
            layer, act, out_dim = DynamicModelBuilder.build_layer(layer_cfg, curr_dim)
            self.layers.append(layer)
            if act:
                self.layers.append(act)
            curr_dim = out_dim

    def forward(self, x):
        for layer in self.layers:
            x = layer(x)
        return x
